import {_ as _sfc_main$c} from "./SimpleDialog.vue_vue_type_script_setup_true_lang-B70uDCdu.js";
import {
    $ as tipShow,
    a as createElementBlock,
    b as createBaseVNode,
    c as createBlock,
    d as defineComponent,
    e as ref,
    F as Fragment,
    f as computed,
    g as useRouter,
    G as api,
    h as useRoute,
    I as renderSlot,
    J as mergeModels,
    j as renderList,
    K as onMounted,
    k as createCommentVNode,
    m as useModel,
    n as normalizeClass,
    o as openBlock,
    p as withCtx,
    q as createVNode,
    r as resolveComponent,
    s as _sfc_main$b,
    t as toDisplayString,
    u as unref,
    v as createTextVNode,
    w as watch,
    X as createSlots,
    Y as createStaticVNode,
    y as isRef,
    Z as useDebounceFn
} from "./index-Dfdf_Rjk.js";
import {_ as _sfc_main$a} from "./IconButton.vue_vue_type_script_setup_true_lang-jAwwuJ2U.js";
import {c as createJobAndExecute} from "./job-DoMclj1u.js";
import {
    _ as _sfc_main$9,
    a as _sfc_main$7,
    b as _sfc_main$6
} from "./SimpleCollapse.vue_vue_type_script_setup_true_lang-rzMMFhj6.js";
import {_ as _sfc_main$5} from "./SimpleInput.vue_vue_type_script_setup_true_lang-D6HMgtcH.js";
import {g as getModelList} from "./model-CGDRSQW4.js";
import {_ as _sfc_main$8, u as useCopy} from "./useCopy-DYzvKz8A.js";
import {a as isJson, j as json, T} from "./vue-codemirror.esm-Qc3mw6Aw.js";

const _sfc_main$4 = /* @__PURE__ */ defineComponent({
    __name: "SimpleNote",
    props: {
        type: {default: "default"}
    },
    setup(__props) {
        return (_ctx, _cache) => {
            return openBlock(), createElementBlock("div", {
                class: normalizeClass(["rounded-md bg-opacity-10 px-4 py-2", {
                    "text-primary bg-primary": _ctx.type === "primary",
                    "text-info bg-info": _ctx.type === "info",
                    "text-warn bg-warn": _ctx.type === "warn",
                    "text-error bg-error": _ctx.type === "error",
                    "color-fade bg-gray-400": _ctx.type === "default"
                }])
            }, [
                renderSlot(_ctx.$slots, "default")
            ], 2);
        };
    }
});
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
    __name: "SimpleSearch",
    props: /* @__PURE__ */ mergeModels({
        placeholder: {default: "搜索"}
    }, {
        "modelValue": {},
        "modelModifiers": {}
    }),
    emits: ["update:modelValue"],
    setup(__props) {
        const search = useModel(__props, "modelValue");
        return (_ctx, _cache) => {
            const _component_SimpleInput = _sfc_main$5;
            return openBlock(), createBlock(_component_SimpleInput, {
                modelValue: search.value,
                "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => search.value = $event),
                placeholder: _ctx.placeholder
            }, createSlots({
                prefix: withCtx(() => [
                    _cache[2] || (_cache[2] = createBaseVNode("div", {class: "i-ph:magnifying-glass-duotone"}, null, -1))
                ]),
                _: 2
            }, [
                search.value ? {
                    name: "suffix",
                    fn: withCtx(() => [
                        createBaseVNode("i", {
                            class: "i-carbon-close-filled cursor-pointer text-sm op50",
                            onClick: _cache[0] || (_cache[0] = ($event) => search.value = "")
                        })
                    ]),
                    key: "0"
                } : void 0
            ]), 1032, ["modelValue", "placeholder"]);
        };
    }
});
const _hoisted_1$2 = {class: "relative flex flex-col gap-4 p-6"};
const _hoisted_2$2 = {class: "flex items-center gap-3"};
const _hoisted_3$1 = {class: "flex cursor-pointer items-center justify-between rounded-md bg-gray/20 px3 py2 hover:bg-gray/30"};
const _hoisted_4$1 = {
    key: 0,
    class: "color-fade"
};
const _hoisted_5 = {
    key: 1,
    class: "color-base op80"
};
const _hoisted_6 = {class: "bg-base py2"};
const _hoisted_7 = {
    key: 1,
    class: "flex flex-col"
};
const _hoisted_8 = {class: "px-2"};
const _hoisted_9 = {
    key: 0,
    class: "max-h-60 flex-1 overflow-y-overlay px-2"
};
const _hoisted_10 = ["onClick"];
const _hoisted_11 = {
    key: 0,
    class: "i-ph:check ml-4 flex-none text-primary"
};
const _hoisted_12 = {
    key: 0,
    class: "flex flex-col gap-1 rounded-md bg-primary/6 p-3"
};
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
    __name: "model-select",
    props: /* @__PURE__ */ mergeModels({
        initModelId: {}
    }, {
        "modelValue": {},
        "modelModifiers": {}
    }),
    emits: ["update:modelValue"],
    setup(__props) {
        const props = __props;
        const selectedModel = useModel(__props, "modelValue");
        const showOptions = ref(false);
        const search = ref("");
        const loading = ref(false);
        const models = ref([]);
        const filtered = ref([]);

        function getModels() {
            const params = {
                query: 1,
                pageSize: 800
            };
            loading.value = true;
            getModelList(params).then((res) => {
                models.value = res.data;
                if (props.initModelId) {
                    selectedModel.value = models.value.find((m) => m.id === props.initModelId);
                }
            }).catch(() => {
                models.value = [];
            }).finally(() => {
                loading.value = false;
            });
        }

        onMounted(() => {
            getModels();
        });
        const triggerFilter = useDebounceFn(() => {
            const _str = search.value.trim().toLowerCase();
            if (!_str) {
                filtered.value = models.value || [];
            } else {
                filtered.value = models.value ? models.value.filter((u) => {
                    const rawStr = "".concat(u.modelName || "").concat(u.description || "");
                    return rawStr.toLowerCase().includes(_str);
                }) : [];
            }
        }, 200);
        watch([search, models], triggerFilter);

        function selectModel(item) {
            selectedModel.value = item;
            showOptions.value = false;
        }

        function gotoCreateModel() {
            const router = useRouter();
            window.open(router.resolve({
                name: "ModelCreate"
            }).href, "_blank");
        }

        return (_ctx, _cache) => {
            var _a, _b, _c, _d, _e;
            const _component_Loading = _sfc_main$6;
            const _component_SimpleSearch = _sfc_main$3;
            const _component_Empty = _sfc_main$7;
            const _component_VDropdown = resolveComponent("VDropdown");
            return openBlock(), createElementBlock("div", _hoisted_1$2, [
                createBaseVNode("div", _hoisted_2$2, [
                    _cache[2] || (_cache[2] = createStaticVNode('<div class="h-12 w-12 flex-center rounded-md bg-primary/20"><i class="i-ph:cube-duotone text-1.8rem text-primary"></i></div><div class="flex"><span class="mr-1 text-red-500">*</span><span class="font-600">选择模型</span></div>', 2)),
                    createBaseVNode("div", {
                        class: normalizeClass(["ml-auto text-sm", selectedModel.value ? "green-badge" : "red-badge"])
                    }, toDisplayString(selectedModel.value ? "已选择" : "必选"), 3)
                ]),
                createBaseVNode("div", {class: "color-fade"}, [
                    _cache[3] || (_cache[3] = createTextVNode(" 请从模型库中选择一个模型，如果没有合适的，您也可以先 ")),
                    createBaseVNode("a", {
                        class: "a-primary",
                        onClick: gotoCreateModel
                    }, " 创建模型 ")
                ]),
                createVNode(_component_VDropdown, {
                    shown: unref(showOptions),
                    "onUpdate:shown": _cache[1] || (_cache[1] = ($event) => isRef(showOptions) ? showOptions.value = $event : null),
                    "auto-size": "",
                    "popper-class": "no-arrow"
                }, {
                    popper: withCtx(() => {
                        var _a2;
                        return [
                            createBaseVNode("div", _hoisted_6, [
                                unref(loading) ? (openBlock(), createBlock(_component_Loading, {
                                    key: 0,
                                    class: "!h-40"
                                })) : (openBlock(), createElementBlock("div", _hoisted_7, [
                                    createBaseVNode("div", _hoisted_8, [
                                        createVNode(_component_SimpleSearch, {
                                            modelValue: unref(search),
                                            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(search) ? search.value = $event : null),
                                            class: "w-full"
                                        }, null, 8, ["modelValue"])
                                    ]),
                                    _cache[5] || (_cache[5] = createBaseVNode("div", {class: "mb-1 mt-2 h-1px w-full bg-gray/20"}, null, -1)),
                                    ((_a2 = unref(filtered)) == null ? void 0 : _a2.length) ? (openBlock(), createElementBlock("ul", _hoisted_9, [
                                        (openBlock(true), createElementBlock(Fragment, null, renderList(unref(filtered), (item) => {
                                            var _a3, _b2;
                                            return openBlock(), createElementBlock("li", {
                                                key: item.id,
                                                class: "w-full flex cursor-pointer items-center justify-between rounded-md hover:bg-hover px2 py1",
                                                onClick: ($event) => selectModel(item)
                                            }, [
                                                createBaseVNode("span", {
                                                    class: normalizeClass(((_a3 = selectedModel.value) == null ? void 0 : _a3.id) === item.id ? "color-primary" : "color-fade")
                                                }, toDisplayString(item.modelName), 3),
                                                ((_b2 = selectedModel.value) == null ? void 0 : _b2.id) === item.id ? (openBlock(), createElementBlock("i", _hoisted_11)) : createCommentVNode("", true)
                                            ], 8, _hoisted_10);
                                        }), 128))
                                    ])) : (openBlock(), createBlock(_component_Empty, {
                                        key: 1,
                                        class: "h-20 flex-center"
                                    }))
                                ]))
                            ])
                        ];
                    }),
                    default: withCtx(() => [
                        createBaseVNode("div", _hoisted_3$1, [
                            !selectedModel.value ? (openBlock(), createElementBlock("span", _hoisted_4$1, "请选择模型")) : (openBlock(), createElementBlock("span", _hoisted_5, toDisplayString(selectedModel.value.modelName), 1)),
                            _cache[4] || (_cache[4] = createBaseVNode("div", {class: "i-ph-caret-down op40"}, null, -1))
                        ])
                    ]),
                    _: 1
                }, 8, ["shown"]),
                selectedModel.value ? (openBlock(), createElementBlock("ul", _hoisted_12, [
                    createBaseVNode("li", null, [
                        _cache[6] || (_cache[6] = createBaseVNode("label", {class: "color-fade"}, "模型名称：", -1)),
                        createBaseVNode("span", null, toDisplayString((_a = selectedModel.value) == null ? void 0 : _a.modelName), 1)
                    ]),
                    createBaseVNode("li", null, [
                        _cache[7] || (_cache[7] = createBaseVNode("label", {class: "color-fade"}, "模型描述：", -1)),
                        createBaseVNode("span", null, toDisplayString(((_b = selectedModel.value) == null ? void 0 : _b.description) || "--"), 1)
                    ]),
                    createBaseVNode("li", null, [
                        _cache[8] || (_cache[8] = createBaseVNode("label", {class: "color-fade"}, "模型类型：", -1)),
                        createBaseVNode("span", null, toDisplayString((_c = selectedModel.value) == null ? void 0 : _c.modelType), 1)
                    ]),
                    createBaseVNode("li", null, [
                        _cache[9] || (_cache[9] = createBaseVNode("label", {class: "color-fade"}, "模型应用范围：", -1)),
                        createBaseVNode("span", null, toDisplayString(((_d = selectedModel.value) == null ? void 0 : _d.scope) || "--"), 1)
                    ]),
                    createBaseVNode("li", null, [
                        _cache[10] || (_cache[10] = createBaseVNode("label", {class: "color-fade"}, "模型标签：", -1)),
                        createBaseVNode("span", null, toDisplayString(((_e = selectedModel.value) == null ? void 0 : _e.tags) || "--"), 1)
                    ])
                ])) : createCommentVNode("", true)
            ]);
        };
    }
});
const _hoisted_1$1 = {class: "relative flex flex-col gap-4 p-6"};
const _hoisted_2$1 = {class: "flex items-center gap-3"};
const exampleInfo = '// paramMeta 样例如下：\n[\n  {"name": "user_id", "description":"用户标识", "demo":"1099", "type":"String", "mode":"equal"},\n  {"name": "time", "description":"时间", "demo":"2024-06-05 23:59:59", "type":"Date", "mode": "range"}\n]\n\n// 则 param 填写样例如下：\n// [KEY] 的取值来自于 paramMeta 中 name 的值\n// [VALUE] 的取值取决于 paramMeta 中 mode 的类型\n// mode 为 equal 时，[VALUE] 为字符串\n// mode 为 range 时，[VALUE] 为对象，可包括 gt/gte/lt/lte 类型\n{\n  "[KEY]": "[VALUE]",\n  "user_id":"1099",\n  "time":{\n    "lt":"2024-06-05 23:59:59",\n    "gt":"2024-05-05 23:59:59"\n  }\n}';
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
    __name: "params-input",
    props: /* @__PURE__ */ mergeModels({
        model: {}
    }, {
        "modelValue": {},
        "modelModifiers": {}
    }),
    emits: ["update:modelValue"],
    setup(__props, {expose: __expose}) {
        const props = __props;
        const modelValue = useModel(__props, "modelValue");
        const paramMeta = computed(() => {
            var _a;
            return ((_a = props.model) == null ? void 0 : _a.paramMeta) || [];
        });
        const required = computed(() => {
            if (!paramMeta.value.length)
                return false;
            if (paramMeta.value.some((u) => u.needed))
                return true;
            return false;
        });

        function validateParam() {
            var _a;
            if (!required.value)
                return true;
            const str = (_a = modelValue.value) == null ? void 0 : _a.trim();
            if (str === "") {
                api.warn("请输入参数");
                return false;
            }
            if (!isJson(str)) {
                api.warn("请输入正确的 JSON 格式");
                return false;
            }
            return true;
        }

        __expose({
            validateParam
        });
        const {copy, copied} = useCopy();
        const {copy: copyMeta, copied: metaCopied} = useCopy();
        return (_ctx, _cache) => {
            var _a, _b;
            const _component_ShikiCode = _sfc_main$8;
            const _component_SimpleCollapse = _sfc_main$9;
            return openBlock(), createElementBlock("div", _hoisted_1$1, [
                createBaseVNode("div", _hoisted_2$1, [
                    _cache[3] || (_cache[3] = createBaseVNode("div", {class: "h-12 w-12 flex-center rounded-md bg-purple/20"}, [
                        createBaseVNode("i", {class: "i-ph:article-duotone text-1.8rem text-purple"})
                    ], -1)),
                    _cache[4] || (_cache[4] = createBaseVNode("div", {class: "font-600"}, " 填写参数 ", -1)),
                    ((_a = unref(paramMeta)) == null ? void 0 : _a.length) ? (openBlock(), createElementBlock("div", {
                        key: 0,
                        class: normalizeClass([unref(required) ? "red-badge" : "gray-badge", "ml-auto text-sm"])
                    }, toDisplayString(unref(required) ? "必填" : "可选"), 3)) : createCommentVNode("", true)
                ]),
                _cache[7] || (_cache[7] = createBaseVNode("div", {class: "color-fade"}, " 请输入 param 参数，需参考相关模型的 paramMeta 字段信息 ", -1)),
                createVNode(unref(T), {
                    modelValue: modelValue.value,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
                    placeholder: "请输入，JSON 格式",
                    style: {
                        background: "white",
                        border: "1px solid #eee",
                        overflowY: "auto",
                        minHeight: "150px",
                        maxHeight: "700px",
                        fontSize: "0.9rem"
                    },
                    "indent-with-tab": true,
                    "tab-size": 2,
                    extensions: [unref(json)()]
                }, null, 8, ["modelValue", "extensions"]),
                ((_b = unref(paramMeta)) == null ? void 0 : _b.length) ? (openBlock(), createBlock(_component_SimpleCollapse, {key: 0}, {
                    title: withCtx(() => _cache[5] || (_cache[5] = [
                        createTextVNode(" paramMeta 信息参考 ")
                    ])),
                    actions: withCtx(() => [
                        createBaseVNode("button", {
                            class: "a-primary",
                            onClick: _cache[1] || (_cache[1] = ($event) => unref(copyMeta)(JSON.stringify(unref(paramMeta), null, 2)))
                        }, toDisplayString(unref(metaCopied) ? "✓ 已复制" : "复制"), 1)
                    ]),
                    default: withCtx(() => [
                        createVNode(_component_ShikiCode, {
                            code: JSON.stringify(unref(paramMeta), null, 2),
                            lang: "json",
                            class: "text-sm"
                        }, null, 8, ["code"])
                    ]),
                    _: 1
                })) : createCommentVNode("", true),
                createVNode(_component_SimpleCollapse, null, {
                    title: withCtx(() => _cache[6] || (_cache[6] = [
                        createTextVNode(" 查看填写样例 ")
                    ])),
                    actions: withCtx(() => [
                        createBaseVNode("button", {
                            class: "a-primary",
                            onClick: _cache[2] || (_cache[2] = ($event) => unref(copy)(exampleInfo))
                        }, toDisplayString(unref(copied) ? "✓ 已复制" : "复制"), 1)
                    ]),
                    default: withCtx(() => [
                        createVNode(_component_ShikiCode, {
                            code: exampleInfo,
                            lang: "json",
                            class: "text-sm"
                        })
                    ]),
                    _: 1
                })
            ]);
        };
    }
});
const _hoisted_1 = {class: "h-full w-full overflow-y-overlay p-4"};
const _hoisted_2 = {class: "mx-auto w-50% flex flex-col gap-6 rounded-lg bg-base px-10 py-8"};
const _hoisted_3 = {class: "relative w-full flex flex-col gap-6"};
const _hoisted_4 = {class: "mt-4 flex-center gap-4"};
const _sfc_main = /* @__PURE__ */ defineComponent({
    __name: "index",
    setup(__props) {
        const route = useRoute();
        const modelIdFromModelPage = computed(() => route.query.modelIdFromModelPage);
        const paramsRef = ref();
        const selectedModel = ref();
        const inputOfParams = ref("");
        const selectedCategory = ref();

        function reset() {
            selectedModel.value = void 0;
            inputOfParams.value = "";
            selectedCategory.value = void 0;
        }

        const jobSuccess = ref(false);

        function handleSubmit() {
            var _a;
            if (!selectedModel.value) {
                api.warn("请选择模型");
                return;
            }
            if (!((_a = paramsRef.value) == null ? void 0 : _a.validateParam()))
                return;
            const req = {
                modelId: selectedModel.value.id,
                param: JSON.parse(inputOfParams.value.trim())
            };
            createJobAndExecute(req).then(() => {
                jobSuccess.value = true;
            });
        }

        return (_ctx, _cache) => {
            const _component_IconButton = _sfc_main$a;
            const _component_SimpleNote = _sfc_main$4;
            const _component_SimpleButton = _sfc_main$b;
            const _component_RouterLink = resolveComponent("RouterLink");
            const _component_SimpleDialog = _sfc_main$c;
            return openBlock(), createElementBlock("div", _hoisted_1, [
                createBaseVNode("div", _hoisted_2, [
                    _cache[8] || (_cache[8] = createBaseVNode("div", {class: "text-1.2rem font-600"}, " 任务创建 ", -1)),
                    unref(tipShow).modelAnalysis ? (openBlock(), createBlock(_component_SimpleNote, {
                        key: 0,
                        class: "flex justify-between"
                    }, {
                        default: withCtx(() => [
                            _cache[5] || (_cache[5] = createBaseVNode("div", null, [
                                createBaseVNode("strong", null, "提示："),
                                createTextVNode("分析任务旨在通过特定模型计算相关数据集，以获得分析结果。创建任务需要 2 个输入：模型、参数。 ")
                            ], -1)),
                            createVNode(_component_IconButton, {
                                class: "ml-4 flex-none text-1.2rem",
                                "icon-class": "i-carbon-close",
                                title: "关闭提示",
                                onClick: _cache[0] || (_cache[0] = ($event) => unref(tipShow).modelAnalysis = false)
                            })
                        ]),
                        _: 1
                    })) : createCommentVNode("", true),
                    createBaseVNode("div", _hoisted_3, [
                        createVNode(_sfc_main$2, {
                            modelValue: unref(selectedModel),
                            "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(selectedModel) ? selectedModel.value = $event : null),
                            "init-model-id": unref(modelIdFromModelPage),
                            class: "w-full border border-base rounded-lg bg-primary/6"
                        }, null, 8, ["modelValue", "init-model-id"]),
                        createVNode(_sfc_main$1, {
                            ref_key: "paramsRef",
                            ref: paramsRef,
                            modelValue: unref(inputOfParams),
                            "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(inputOfParams) ? inputOfParams.value = $event : null),
                            model: unref(selectedModel),
                            class: "w-full border border-base rounded-lg bg-purple/6"
                        }, null, 8, ["modelValue", "model"])
                    ]),
                    createBaseVNode("div", _hoisted_4, [
                        createVNode(_component_SimpleButton, {
                            class: "!h-10",
                            onClick: reset
                        }, {
                            default: withCtx(() => _cache[6] || (_cache[6] = [
                                createTextVNode(" 重置 ")
                            ])),
                            _: 1
                        }),
                        createVNode(_component_SimpleButton, {
                            disabled: !unref(selectedModel),
                            type: "primary",
                            class: "!h-10",
                            onClick: handleSubmit
                        }, {
                            default: withCtx(() => _cache[7] || (_cache[7] = [
                                createBaseVNode("i", {class: "i-ph:navigation-arrow-duotone mr-2"}, null, -1),
                                createTextVNode(" 创建并执行分析任务 ")
                            ])),
                            _: 1
                        }, 8, ["disabled"])
                    ])
                ]),
                createVNode(_component_SimpleDialog, {
                    modelValue: unref(jobSuccess),
                    "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => isRef(jobSuccess) ? jobSuccess.value = $event : null),
                    class: "flex-center flex-col p-4 !h-50 !w-80"
                }, {
                    default: withCtx(() => [
                        _cache[13] || (_cache[13] = createBaseVNode("div", {class: "i-ph:check-circle-duotone mb-3 text-4rem text-green"}, null, -1)),
                        _cache[14] || (_cache[14] = createBaseVNode("p", null, "任务已经开始执行", -1)),
                        createBaseVNode("p", null, [
                            _cache[10] || (_cache[10] = createTextVNode(" 请前往 ")),
                            createVNode(_component_RouterLink, {
                                to: "/job/list",
                                class: "a-primary"
                            }, {
                                default: withCtx(() => _cache[9] || (_cache[9] = [
                                    createTextVNode(" 任务列表 ")
                                ])),
                                _: 1
                            }),
                            _cache[11] || (_cache[11] = createTextVNode(" 页面进行查看 "))
                        ]),
                        createVNode(_component_SimpleButton, {
                            type: "primary",
                            class: "mt-4",
                            onClick: _cache[3] || (_cache[3] = ($event) => jobSuccess.value = false)
                        }, {
                            default: withCtx(() => _cache[12] || (_cache[12] = [
                                createTextVNode(" 好的 ")
                            ])),
                            _: 1
                        })
                    ]),
                    _: 1
                }, 8, ["modelValue"])
            ]);
        };
    }
});
export {
    _sfc_main as default
};
